package controllor

import (
	"fitness/internal/service"
	"fitness/pkg/middleware"
	"github.com/gin-gonic/gin"
)

type DictController struct {
	DictService *service.DictService
	Rbac        *middleware.Rbac
}

func NewDictController(DictService *service.DictService, rbac *middleware.Rbac) *DictController {
	return &DictController{
		DictService: DictService,
		Rbac:        rbac,
	}
}

func (api *DictController) InitApiRouter(engine *gin.Engine) {
	//字典
	Dict := engine.Group("/api/dict")
	{
		//获取简略字典
		Dict.GET("/:code/options", middleware.Jwt, api.DictService.GetDictOptions)
		//字典分页
		Dict.GET("/page", middleware.Jwt, api.DictService.GetDictPage)
		//字典表单
		Dict.GET("/form/:dictId", middleware.Jwt, api.DictService.GetDictForm)
		//保存
		Dict.POST("", middleware.Jwt, api.Rbac.RbacAuth("sys:dict:add"), api.DictService.SaveDict)
		//修改字典
		Dict.PUT("/:dictId", middleware.Jwt, api.Rbac.RbacAuth("sys:dict:edit"), api.DictService.UpdateDict)
		//删除字典
		Dict.DELETE("/:dictIds", middleware.Jwt, api.Rbac.RbacAuth("sys:dict:delete"), api.DictService.DeleteDict)
	}
}
